#pragma once

#include <iostream>
#include <set>
#include <math.h>

#include "basegameentity.h"
#include "entitymanager.h"
#include "telegram.h"
#include "zakengine/zak.h"

using namespace zak;

class BaseGameEntity;

class MessageDispatcher 
{
public:
	
	// Singleton
	static MessageDispatcher* Instance();

	// Send a message
	void DispatchMessage(double	dTimeDelay,
						  int		iSender,
						  int		iReceiver,
						  int		iMessage,
						  void*		extraInfo);

	// Send Delayed Messages
	void DispatchDelayedMessages();

private:
	
	// Set that sorts messages by their delay time
	std::set<Telegram> PriorityQueue;

	// Calls the function to handle messages of the receiving entity
	void Discharge(BaseGameEntity* pReceiver, const Telegram& msg);
};